import argparse
import numpy as np
import torch
import torch.nn.functional as F


def str2bool(v):
    if isinstance(v, bool):
        return v
    if v.lower() in ('yes', 'true', 't', 'y', '1'):
        return True
    elif v.lower() in ('no', 'false', 'f', 'n', '0'):
        return False
    else:
        raise argparse.ArgumentTypeError('Boolean value expected.')


def getrightlori(angle_list, cor_angle):
    angle_list = np.append(angle_list, 360.0)
    dis_list = list(map(lambda x: abs(x-cor_angle), angle_list))
    result = dis_list.index(min(dis_list))
    return result if result != len(angle_list)-1 else 0


if __name__ == '__main__':
    a = torch.rand((4, 4))
    temp1 = torch.min(a, dim=1)
    temp2 = torch.min(temp1[0], dim=0)
    pre_y = temp1[1][temp2[1]]

    for i in range(4):
        a[i][i] = i

    pos_dist = torch.diag(a)

    triplet_dist_g2s = pos_dist - a
    print(a)
    print(triplet_dist_g2s)

    # if ()